<template>
	<view>
		<view class="list_item" v-for="(listItem,index) in orderList" :key="index">
			<view class="info_panel">
				<image class="image" :src="listItem.image" mode=""></image>
				<view class="info">
					<view class="info_header">
						<viwe class="title">
							<text class="titile_text">{{listItem.name}}</text>
							<view class="sign green" v-if="listItem.zhengce == enums['服务政策']['公益']">公益</view>
							<view class="sign orange" v-if="listItem.zhengce == enums['服务政策']['常规']">常规</view>
						</viwe>
						<view class="price" v-if="listItem.money && listItem.money>0">￥{{listItem.money | toFixed(2)}}/次</view>
						<view class="price gratis" v-else>免费</view>
					</view>
					<view class="info_container">
						<view class="text">
							{{listItem.content}}
						</view>
					</view>
					<veiw class="info_footer">
						<view class="organization check" v-if="listItem.state == enums['管理服务类型']['审核中']">审核中</view>
						<view class="organization serve" v-if="listItem.state == enums['管理服务类型']['服务中']">服务中</view>
						<view class="organization out" v-if="listItem.state == enums['管理服务类型']['已下架']">已下架</view>
						<view class="count">{{listItem.count || 0}}人购买</view>
					</veiw>
				</view>
			</view>
			<view class="price_panel">
				<view class="btn_panel">
					<view class="btn_left">
						<!-- <view class="cancel" v-if="listItem.type == 1">取消订单</view> -->
					</view>
					<view class="btn_right">
						<view class="cancel" v-if="listItem.state == enums['管理服务类型']['审核中']" @tap="cancelServe(listItem.id)">取消上架</view>
						<view class="cancel" v-if="listItem.state == enums['管理服务类型']['服务中']" @tap="offDownServe(listItem.id)">下架服务</view>
						<view class="cancel" v-if="listItem.state == enums['管理服务类型']['已下架']" @tap="delService(listItem.id)">删除服务</view>
						<view class="confirm" v-if="listItem.state == enums['管理服务类型']['审核中'] || listItem.state == enums['管理服务类型']['服务中']" @tap="edit(listItem.id)">修改服务</view>
						<view class="confirm" v-if="listItem.state == enums['管理服务类型']['已下架']" @tap="resetUpServe(listItem.id)">重新上架</view>
					</view>
				</view>
			</view>
		
		</view>
	</view>
</template>

<script>
	import * as serveApi from '@/api/orgApi/serve.js';
	export default {
		props: {
			orderList: null
		},
		data() {
			return {
				enums: this.$enums,
			};
		},
		methods: {
			toDetail(data) {
				uni.navigateTo({
					url: `/pages/mine/order/orderDetail/orderDetail?id=${data.id}`
				});
			},
			resetUpServe(id){
				serveApi.startAgain({id:id}).then(res => {
					if (res.code === 0) {
						this.$emit('search');
					}
				}).catch((e)=>{
					uni.showToast({
						title: e.msg,
						icon: 'none',
						duration: 1000
					});
				});
			},
			cancelServe(id) {
				serveApi.cancelServe({id:id}).then(res => {
					if (res.code === 0) {
						this.$emit('search');
					}
				}).catch((e)=>{
					uni.showToast({
						title: e.msg,
						icon: 'none',
						duration: 1000
					});
				});
			},
			delService(id) {
				serveApi.delService({id:id}).then(res => {
					if (res.code === 0) {
						this.$emit('search');
					}
				}).catch((e)=>{
					uni.showToast({
						title: e.msg,
						icon: 'none',
						duration: 1000
					});
				});
			},
			offDownServe(id) {
				serveApi.offDownServe({id:id}).then(res => { 
					if (res.code === 0) {
						this.$emit('search');
					}
				}).catch((e)=>{
					uni.showToast({
						title: e.msg,
						icon: 'none',
						duration: 1000
					});
				});
			},
			edit (ID) {
				if(ID) {
					uni.navigateTo({
						url: `/pages/orgPage/mine/publishingService/publishingService?id=${ID}`
					});
				}
			}
		}
	}
</script>

<style lang="stylus">

</style>
